<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  index_model.php
//  phpweb
//  
//  Created by WillLee on 2011-06-28.
//  Copyright 2011 lishuzu. All rights reserved.
// 



class index_model extends CI_Model
{
		function __construct(){
			parent::__construct();
			$this->load->model('work_model');
			//加载缓存类
			$this->load->library('datacache');
		}
		
		function get_index_data(){
			//加载主页缓存文件
			$cachefilename = APPPATH."cache/data_indexcache.php";
			$cachefile = '';
			$cachetime = 600;
			if(file_exists($cachefilename) && (filemtime($cachefilename) + $cachetime) > time()) {
			 	$cachefile = include_once($cachefilename);
				$data = $config['indexcache'];
			 } else {
				$this->datacache->index_cache();
				$cachefile = include_once($cachefilename);
				$data = $config['indexcache'];
			}
			//推荐作品
			if ($data['recommend']) {
				foreach ($data['recommend'] as $key => $value) {
					$value['avatar_small'] = avatar($value['uid'], 'small');
					$value['thumbimg'] = get_workimg($value['filepath'], 'thumb', 'url');

					$value['url'] = base_url().'work/index/'.$value['wid'];
					$value['key'] = get_workkey($value['wid']);
					$value['tags'] = empty($value['tag'])?array():unserialize($value['tag']);
					$data['recommend'][$value['wid']] = $value;
				}
			}
			
			if ($data['new']) {
				foreach ($data['new'] as $key => $value) {
					$value['avatar_small'] = avatar($value['uid'], 'small');
					$value['thumbimg'] = get_workimg($value['filepath'], 'thumb', 'url');

					$value['url'] = base_url().'work/index/'.$value['wid'];
					$value['key'] = get_workkey($value['wid']);
					$value['tags'] = empty($value['tag'])?array():unserialize($value['tag']);
					$data['new'][$value['wid']] = $value;
				}
			}
			
			if ($data['hotsold']) {
				foreach ($data['hotsold'] as $key => $value) {
					$value['avatar_small'] = avatar($value['uid'], 'small');
					$value['thumbimg'] = get_workimg($value['filepath'], 'thumb', 'url');

					$value['url'] = base_url().'work/index/'.$value['wid'];
					$value['key'] = get_workkey($value['wid']);
					$value['tags'] = empty($value['tag'])?array():unserialize($value['tag']);
					$data['hotsold'][$value['wid']] = $value;
				}
			}
			
			if ($data['designer']) {
				foreach ($data['designer'] as $key => $value) {
					$value['avatar_small'] = avatar($value['uid'], 'small');
					$data['designer'][$value['uid']] = $value;
				}
			}
			
			return $data;
		}
}
?>